package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.SysCompanyInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysCompanyReportSuggest;
import com.ruoyi.system.service.ISysCompanyReportSuggestService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 诊断报告建议模版库Controller
 * 
 * @author ruoyi
 * @date 2023-08-19
 */
@Api(tags = "企业诊断报告建议模版库")
@RestController
@RequestMapping("/system/suggest")
public class SysCompanyReportSuggestController extends BaseController
{
    @Autowired
    private ISysCompanyReportSuggestService sysCompanyReportSuggestService;

    /**
     * 查询诊断报告建议模版库列表
     */
    @ApiOperation(value = "查询诊断报告建议模版库列表")
    //   @PreAuthorize("@ss.hasPermi('system:info:list')")
    @GetMapping("/list")
    public AjaxResult list(SysCompanyReportSuggest sysCompanyReportSuggest)
    {
        if(!getLoginUser().getUser().isAdmin()){
            sysCompanyReportSuggest.setUserId(getLoginUser().getUserId());
        }
        List<SysCompanyReportSuggest> list = sysCompanyReportSuggestService.selectSysCompanyReportSuggestList(sysCompanyReportSuggest);
        return AjaxResult.success(list);
    }

    /**
     * 查询诊断报告建议模版库列表
     */
   // @PreAuthorize("@ss.hasPermi('system:suggest:list')")
    @GetMapping("/page")
    @ApiOperation(value = "查询诊断报告建议模版库列表(分页)")
    public TableDataInfo listPage(SysCompanyReportSuggest sysCompanyReportSuggest)
    {
        startPage();
        if(!getLoginUser().getUser().isAdmin()){
            sysCompanyReportSuggest.setUserId(getLoginUser().getUserId());
        }
        List<SysCompanyReportSuggest> list = sysCompanyReportSuggestService.selectSysCompanyReportSuggestList(sysCompanyReportSuggest);
        return getDataTable(list);
    }

    /**
     * 导出诊断报告建议模版库列表
     */
   // @PreAuthorize("@ss.hasPermi('system:suggest:export')")
    @Log(title = "诊断报告建议模版库", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysCompanyReportSuggest sysCompanyReportSuggest)
    {
        List<SysCompanyReportSuggest> list = sysCompanyReportSuggestService.selectSysCompanyReportSuggestList(sysCompanyReportSuggest);
        ExcelUtil<SysCompanyReportSuggest> util = new ExcelUtil<SysCompanyReportSuggest>(SysCompanyReportSuggest.class);
        util.exportExcel(response, list, "诊断报告建议模版库数据");
    }

    /**
     * 获取诊断报告建议模版库详细信息
     */
  //  @PreAuthorize("@ss.hasPermi('system:suggest:query')")
    @GetMapping(value = "/{suggestId}")
    @ApiOperation(value = "获取诊断报告建议模版库详细信息")
    public AjaxResult getInfo(@PathVariable("suggestId") Long suggestId)
    {
        return AjaxResult.success(sysCompanyReportSuggestService.selectSysCompanyReportSuggestBySuggestId(suggestId));
    }

    /**
     * 新增诊断报告建议模版库
     */
   // @PreAuthorize("@ss.hasPermi('system:suggest:add')")
    @Log(title = "诊断报告建议模版库", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation(value = "新增诊断报告建议模版库")
    public AjaxResult add(@RequestBody SysCompanyReportSuggest sysCompanyReportSuggest)
    {
        sysCompanyReportSuggest.setCreateBy(getLoginUser().getUsername());
        sysCompanyReportSuggest.setUserId(getLoginUser().getUserId());
        return toAjax(sysCompanyReportSuggestService.insertSysCompanyReportSuggest(sysCompanyReportSuggest));
    }

    /**
     * 修改诊断报告建议模版库
     */
  //  @PreAuthorize("@ss.hasPermi('system:suggest:edit')")
    @Log(title = "诊断报告建议模版库", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation(value = "修改诊断报告建议模版库")
    public AjaxResult edit(@RequestBody SysCompanyReportSuggest sysCompanyReportSuggest)
    {
        sysCompanyReportSuggest.setUpdateBy(getLoginUser().getUsername());
        return toAjax(sysCompanyReportSuggestService.updateSysCompanyReportSuggest(sysCompanyReportSuggest));
    }

    /**
     * 删除诊断报告建议模版库
     */
  //  @PreAuthorize("@ss.hasPermi('system:suggest:remove')")
    @Log(title = "诊断报告建议模版库", businessType = BusinessType.DELETE)
	@DeleteMapping("/{suggestIds}")
    @ApiOperation(value = "删除诊断报告建议模版库")
    public AjaxResult remove(@PathVariable Long[] suggestIds)
    {
        return toAjax(sysCompanyReportSuggestService.deleteSysCompanyReportSuggestBySuggestIds(suggestIds));
    }
}
